devtools::install()
## Skipping 2 packages not available: pasilla, DESeq2
##   
   checking for file ‘/Users/Thadryan/Dropbox (Partners HealthCare)/Workspace/RPackages/ContrApption/DESCRIPTION’ ...
  
✓  checking for file ‘/Users/Thadryan/Dropbox (Partners HealthCare)/Workspace/RPackages/ContrApption/DESCRIPTION’
## 
  
─  preparing ‘ContrApption’: (1s)
## 
  
   checking DESCRIPTION meta-information ...
  
✓  checking DESCRIPTION meta-information
## 
  
─  checking for LF line-endings in source and make files and shell scripts (349ms)
## 
  
─  checking for empty or unneeded directories
## 
  
─  building ‘ContrApption_0.0.1.9000.tar.gz’
## 
  
   
## 
Running /Library/Frameworks/R.framework/Resources/bin/R CMD INSTALL \
##   /var/folders/g0/2sgkg3j573v5c8tt_dqgkjmw0000gp/T//RtmpV00gpr/ContrApption_0.0.1.9000.tar.gz \
##   --install-tests 
## * installing to library ‘/Users/Thadryan/Dropbox (Partners HealthCare)/Workspace/HFrEF_v_HFpEF_FullModel/renv/library/R-3.6/x86_64-apple-darwin15.6.0’
## * installing *source* package ‘ContrApption’ ...
## ** using staged installation
## ** R
## ** inst
## ** byte-compile and prepare package for lazy loading
## ** help
## *** installing help indices
## ** building package indices
## ** installing vignettes
## ** testing if installed package can be loaded from temporary location
## ** testing if installed package can be loaded from final location
## ** testing if installed package keeps a record of temporary installation path
## * DONE (ContrApption)
library(ContrApption)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union

suppressMessages(library(DESeq2))
## Warning: package 'S4Vectors' was built under R version 3.6.3
## Warning: package 'GenomeInfoDb' was built under R version 3.6.3
## Warning: package 'DelayedArray' was built under R version 3.6.3
#> Warning: package 'S4Vectors' was built under R version 3.6.3
#> Warning: package 'GenomeInfoDb' was built under R version 3.6.3
#> Warning: package 'DelayedArray' was built under R version 3.6.3
suppressMessages(library(pasilla))

# loads sample annotation from the pasilla package
pasAnno <- system.file("extdata", "pasilla_sample_annotation.csv", package = "pasilla", mustWork = TRUE)

# read in the sample data
coldata <- read.csv(pasAnno, row.names = 1)

# select relevant columns
coldata <- data.frame(coldata[ , c("condition","type")])

# remove un-needed characters
rownames(coldata) <- gsub("fb", "", rownames(coldata))

# loads counts file from the pasilla package 
pasCts <- system.file("extdata", "pasilla_gene_counts.tsv", package = "pasilla", mustWork = TRUE)

# reads counts of genes
cts <- read.csv(pasCts, sep = "\t", row.names = "gene_id")

# make sure the order is correct
cts <- cts[, rownames(coldata)]

# create a DESeq2 dataset from the metadata and counts
dds <- DESeq(DESeqDataSetFromMatrix(countData = cts, colData = coldata, design = ~ condition))
## estimating size factors
## estimating dispersions
## gene-wise dispersion estimates
## mean-dispersion relationship
## final dispersion estimates
## fitting model and testing
#> estimating size factors
#> estimating dispersions
#> gene-wise dispersion estimates
#> mean-dispersion relationship
#> final dispersion estimates
#> fitting model and testing

normCounts <- counts(dds, normalized = TRUE)

res <- results(dds, tidy = TRUE) %>% 
  data.frame %>% 
  filter(padj < 0.05)

normCountsSig <- normCounts %>%
  data.frame %>% 
  filter(rownames(.) %in% res$row)

# datatable(normCountsSigShared, style="bootstrap", selection = 'multiple')# devtools::install(); library(ContrApption);
library(DT)
library(crosstalk)

normCountsSigShared <- SharedData$new(normCountsSig)
ContrApption(data = normCountsSigShared, annotation = coldata)
datatable(
  normCountsSigShared, 
  style = "bootstrap",
  class = "compact",
  width = "100%",
  options = list(),
  selection = 'single'
)
ContrApption(data = normCountsSigShared, annotation = coldata)